<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .tab {
            height: 300px;
            width: 900px;
            margin: 100px auto;
        }

        li {
            display: inline-block;
            list-style: none;
            font-size: 18px;
            height: 39px;
            line-height: 39px;
            padding: 0px 20px;
        }

        .tab_list .current {
            background-color: red;
            color: white;
        }

        .tab_list ul {
            border: 1px solid #ccc;
            background-color: #eee;
            /* border-bottom: 1px solid #ccc; */
        }

        .item {
            display: none;
        }
    </style>
</head>

<body>
    <div class="tab">
        <div class="tab_list">
            <ul>
                <li class="current">商品介绍</li>
                <li>规格与包装</li>
                <li>售后保障</li>
                <li>商品评价</li>
                <li>手机社区</li>
            </ul>
        </div>
        <div class="tab_con">
            <div class="item" style="display:block">商品介绍内容</div>
            <div class="item">规格与包装内容</div>
            <div class="item">售后保障内容</div>
            <div class="item">商品评价内容</div>
            <div class="item">手机社区内容</div>
        </div>
    </div>

    <script>
        var lis = document.querySelector('.tab_list').querySelectorAll('li');
        var items = document.querySelector('.tab_con').querySelectorAll('.item');
        
        for (var i = 0; i < lis.length; i++) {
            //开始时设置索引号
            lis[i].setAttribute('index', i);
            //触发点击事件
            lis[i].onclick = function () {
                var index = this.getAttribute('index');
                for (var i = 0; i < lis.length; i++) {
                    lis[i].className = '';
                }
                this.className = 'current';
                for (var i = 0; i < items.length; i++) {
                    items[i].style.display = 'none';
                }
                items[index].style.display = 'block';
            }
        }
    </script>
</body>

</html>